package cs422.group1.projectsquirrel;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ObservationHistory extends ListActivity {
	
	ArrayList<ObservationData> observations;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.observationhistory);

        
        observations = ObservationDataManager.loadObservations();
        	
        ListAdapter adapter = createListAdapter();
        setListAdapter(adapter);
        

               
    }
    
    
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
    	ObservationData o = observations.get(position);
    	
    	ObservationDataManager.loadObservation(o);
    	
    	Intent intent = new Intent(this, RecordObservation.class);
    	startActivity(intent);
    }
    
    private ListAdapter createListAdapter()
    {
    	ArrayList<String> values = new ArrayList<String>();
    	
    	for (ObservationData o : observations)
    	{
    		values.add(o.toString());
    	}
    	
    	ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.listtextview, R.id.row_number, values);
    	return adapter;
    }
}
